<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">仪表盘</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <div class="sel">
        近5天各数据情况显示
      </div>
      <div class="items"
           id='ca'
           ref='conWidth'>
        <h4>收入情况折线图</h4>
        <div id="custom"></div>
      </div>
      <div class="items">
        <h4>销售情况折线图</h4>
        <div id="main3"></div>
      </div>
      <div class="items">

        <h4>各家油卡消费情况饼图</h4>
        <div id="card"
             style='height:300px;'></div>
      </div>
      <div class="items">
        <h4>各会员消费情况饼图</h4>
        <div id='main'
             style='height:300px;'></div>
      </div>
    </el-card>
    <el-card>
      <h3>以下为余额不足10000元的客户，请提醒客户及时充值</h3>
      <el-table :data="data"
                border
                stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="name"
                         label="客户名称">
        </el-table-column>
        <el-table-column prop="totals"
                         label="客户余额"></el-table-column>
      </el-table>
    </el-card>

  </div>
</template>
<script>
var echarts = require('echarts')
export default {
  data () {
    return {
      tz: 0,
      value: 5,
      options: [{
        value: 7,
        label: '近7天各数据情况显示'
      }, {
        value: 14,
        label: '近2周各数据情况显示'
      }, {
        value: 30,
        label: '近1个月各数据情况显示'
      }],
      data: []
    }
  },
  created () {
    this.change()
    this.getTz()
  },
  mounted () {
    this.getWidth()
    this.getData()
    this.getCustom()

  },
  methods: {
    selects (item) {
      this.value = item
      this.getData()
    },
    getData () {
      //销售情况折线图
      var myChart3 = echarts.init(document.getElementById('main3'))
      this.$http.get('/api/reportUrealData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        myChart3.setOption(res.data);
      })
      ////客户情况报表 
      var myChart = echarts.init(document.getElementById('main'))
      this.$http.get('/api/reportShouruData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        myChart.setOption(res.data);
      })

      //两种色号的油进出货情况

      //油卡情况报表
      var card = echarts.init(document.getElementById('card'))
      this.$http.get('/api/reportCardData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        card.setOption(res.data)
      })
      //收入情况（散户，客户，油卡）管理报表
      var custom = echarts.init(document.getElementById('custom'))
      this.$http.get('/api/reportCustomData', {
        params:
          { tz: this.tz, das: this.value }
      }).then(res => {
        let option = res.data
        custom.setOption(option);
        // window.onresize = custom.resize;
        window.onresize = function () {
          custom.resize();
          myChart3.resize();
          card.resize();
          myChart.resize();
        }
      })
      custom.resize();
      myChart3.resize();
      card.resize();
      myChart.resize();
    },
    //获取剩余资金在10000万以下的会员
    getCustom () {
      this.$http.get('/api/customlt').then(res => {
        if (res.status === 200) {
          this.data = res.data
        }
      })
      // window.onresize = custom.resize;
    },
    //查询当前是手机端 ，还是PC端
    _isMobile () {
      let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
      return flag;
    },
    change () {
      if (this._isMobile()) {
        // this.$router.push('panel')
        // this.$router.replace('/m_index');
      } else {
        // alert("pc端");
        // this.$router.replace('/pc_index');
      }
    },
    //获取当前时区
    getTz () {
      const das = new Date()
      this.tz = (-(das.getTimezoneOffset() / 60))
    },
    getWidth () {
      let aa = this.$refs.conWidth.clientWidth + 'px';
      console.log(aa)
    },
  },
  watch: {
    // this.chart.resize()
  }
}
</script>
<style scoped>
.items {
  width: 98%;
  height: 400px;
  color: #fff !important;
  margin-bottom: 20px;
  padding-top: 10px;
}
.el-card .items h4 {
  text-align: center;
  font-size: 18px;
  line-height: 30px;
  height: 30px;
  color: #333;
}
.el-card .items div {
  width: 100%;
  height: 360px;
  margin: 0 auto;
}

h3 {
  padding: 20px 0;
}
</style>